package cn.itlaobing.eshop.web.servlet;

import cn.itlaobing.eshop.entity.Itlb_goods;
import cn.itlaobing.eshop.exception.BusinessException;
import cn.itlaobing.eshop.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: WangDong
 * @Date: 2017/11/15 21:46
 */
@WebServlet("/goods/detailservlet")
public class DetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id=req.getParameter("id");
        GoodsService goodsService=new GoodsService();

        Itlb_goods itlbGoods=null;
        try {
            itlbGoods=goodsService.query(Integer.parseInt(id));
            String s=itlbGoods.getDetail();//整个长的图片
            String array[]=s.split(";");//截出来的短的图片
            System.out.println(array.length);


            req.setAttribute("IMG",array);
            req.setAttribute("DETAIL",itlbGoods);
            req.getRequestDispatcher("/WEB-INF/views/detail.jsp").forward(req,resp);
        } catch (BusinessException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
